import cTitle from 'components/title';
import { scrollMixin } from "utils/mixin";
// import diyBackGround from "../member/balance/componet/diyBackGround.vue";
import diyBackGround from "components/diyBackGround";
export default {
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      toi: this.fun.getKeyByI(),
      selected: '',
      all: [],
      //收入积分
      income: [],
      //消费积分
      out: [],
      recordsList: [],

      integral: '',

      // new
      statusValue: 0,
      selectShow: false,
      selectType: 0,
      record_list: [],
      money_arr: [],
      currentDate: new Date(),
      maxDate: new Date(),
      show: false,
      postDate: "",
      noneShow: false,
      selectTimeDate: "",
      // 业务类型数组
      source_comment:[],
      selectTapInd: 0,

      //more
      isLoadMore: true,
      page: 1,
      total_page: 0,
      point_mode: '',
      list: [],
      endTime: '',//到期时间
    };
  },
  methods: {
    // initData() {
    //   this.selected = "";
    //   this.isLoadMore = true;
    //   this.page = 1;
    //   this.total_page = 0;
    //   this.recordsList = [];
    // },
    // swichTabTItem() {
    //   this.getIntegralInfo(this.selected);
    // },
    // 正常滑落会员信息
    getkangyanguserinfo(){
        var that = this;
        $http.post("shijiahe.kangyang_userinfo", { 
            uid: localStorage.getItem("uid") ? localStorage.getItem("uid") : localStorage.getItem("mid")
            // uid: 137538
        }).then(res => {
            if (res.result == 1) {
                var obj = res.data;
                that.endTime = obj ? obj.end_time : '';
            }
            
        });
    },
    expand(item) {
      this.$forceUpdate();
      this.$router.push(this.fun.getUrl("integraldetail", { id: item.id }));
    },
    getData(type) {
      let json = {
        code: this.point_mode,
        uid: window.localStorage.getItem("uid") ? window.localStorage.getItem("uid") : '',
        page: this.page
      };
      $http
        .post("shijiahe.tixianPoint", json, "加载中")
        .then(response => {
            console.log(response,'responseresponse');
          if (response.result === 1) {
            
            this.isLoadMore = true;
            // this.noneShow = false;
            this.total_page = response.data.last_page;
            if (!this.total_page) {
              this.total_page = 0;
            }
            this.list = response.data.data;
            console.log(this.list,'listttttttt');
          } else {
            // this.noneShow = true;
            this.isLoadMore = false; // 防止多次请求分页数据
            this.record_list = [];
          }
        })
        .catch(error => {
          console.log(error);
        });
    },

    //获取更多数据
    getMoreData() {
      if (!this.isLoadMore) return;
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page += 1;
        let json = {
            code: this.point_mode,
            uid: window.localStorage.getItem("uid") ? window.localStorage.getItem("uid") : '',
            page: this.page
        };
        $http.post("shijiahe.tixianPoint", json, "加载中").then(response => {
          if (response.result === 1) {
            var nextPageData = response.data.data;
            this.list = [...this.list,...nextPageData];
            // this.money_arr = Object.assign(this.money_arr, response.data.point_arr);
            // for (const key in nextPageData) {
            //   if (this.record_list.data[key]) {
            //     this.$set(this.record_list.data, key, [...this.record_list.data[key], ...nextPageData[key]]);
            //   } else {
            //     this.$set(this.record_list.data, key, nextPageData[key]);
            //   }
            // }
            this.isLoadMore = true;
          } else {
            this.page = this.page - 1;
            this.isLoadMore = false;
          }
        });
      }
    },
    detailsTo(info) {
      this.$router.push(this.fun.getUrl("details", { item: info }));
    },
    formatter(type, val) {
      if (type === "year") {
        return `${val}年`;
      } else if (type === "month") {
        return `${val}月`;
      }
      return val;
    },
    selectStatus(key) {
      this.init();
      this.statusValue = key;
      this.getData();
    },
    selectTap(key) {
      this.init();
      this.selectType = key;
      this.selectTapInd = key;
      this.getData();
    },
    pickConfirm(e) {
      this.postDate = this.timestampToTime(Date.parse(e));
      this.show = false;
      this.init();
      this.getData();
    },
    init() {
      this.isLoadMore = true;
      this.page = 1;
      this.total_page = 0;
      this.record_list = [];
      this.money_arr = [];
      this.selectShow = false;
    },
    //将时间戳转换成正常时间格式
    timestampToTime: function (timestamp, key) {
      if (!Number(timestamp) || timestamp == "") {
        return "";
      }
      let date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
      console.log(date,'date111111')
      let Y = date.getFullYear() + "-";
      let M = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-";
      let D = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
      console.log(Y + M + D,'YMD')
      return Y + M + D;
    },
  },
  filters: {
    timestampToDateTime(timestamp) {
        // 将秒级时间戳转换为毫秒级
        const date = new Date(timestamp * 1000);
        // 提取各时间部分
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始
        const day = String(date.getDate()).padStart(2, '0');
        const hours = String(date.getHours()).padStart(2, '0');
        const minutes = String(date.getMinutes()).padStart(2, '0');
        const seconds = String(date.getSeconds()).padStart(2, '0');
        
        return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    }
  },
  activated() {
    // integral
    this.integral = this.$route.params.title == 'fuli' ? '月月赚' : this.$route.params.title == 'gongxiang' ? '共享奖' : this.$route.params.title == 'tuanpin' ? '团拼奖' : this.$route.params.title == 'fenhong' ? '分红' : this.$route.params.title == 'zhutui' ? '直推奖' : this.$route.params.title == 'guanli' ? '管理奖' : this.$route.params.title == 'zhuli' ? '助力奖' : '';
    this.point_mode = JSON.stringify(this.$route.params.point_mode);
    this.noneShow = this.$route.params.title == 'fuli' ? true : false;
    console.log(this.$route.params,'this.$route.params');
    // this.init();
    // this.toi = this.fun.getKeyByI();
    this.getData();
    // this.fun.setWXTitle(this.integral + '列表');
    this.timestampToTime(Date.parse(1763025610))
    this.getkangyanguserinfo();
  },
  components: { cTitle, diyBackGround }
};